<!-- 床位查询页 -->
<template>
  <!-- 面包屑 -->
  <div style="margin: 20px;">
    <el-breadcrumb separator="/" style="line-height:35px">
      <el-breadcrumb-item><span style="color: #7A7A7A;">服务管理</span></el-breadcrumb-item>
      <el-breadcrumb-item><span style="color: #7A7A7A;">接待管理</span></el-breadcrumb-item>
      <el-breadcrumb-item><span style="color: #0468FF;font-weight: bold">床位查询</span></el-breadcrumb-item>
    </el-breadcrumb>
  </div>

  <!-- 搜索栏 -->
  <el-card style="margin: 20px;height: 70px;border: 0" shadow="never">
    <el-form>
      <el-row :gutter="50">
        <el-col :span="8">
          <el-form-item label="房间号">
            <el-input placeholder="请输入房间号" v-model="searchForm.number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="床位状态" style="">
            <el-select v-model="searchForm.status"
                       @change="loadBed"
                       placeholder="请选择床位状态">
              <el-option label="全部" value=""></el-option>
              <el-option label="空床" value="空床"></el-option>
              <el-option label="已占用" value="已占用"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item>
            <el-button @click="resetSearch">重置</el-button>
            <el-button type="primary" @click="loadBed">查询</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </el-card>

  <!-- 列表 -->
  <el-card style="margin:20px;border: 0" shadow="never">
    <el-table :data="currentTableData" height="550px"
              :row-style="{'height':'50px'}"
              :cell-style="{'color':'#000'}"
              :header-cell-style="{
                'background-color': '#f2f2f2',
                'color': '#000',
                'height':'50px'
              }">
      <el-table-column prop="bedNumber" label="床位号" align="center"/>
      <el-table-column prop="status" label="状态" align="center"/>
      <el-table-column prop="floor" label="所属楼层" align="center"/>
      <el-table-column prop="type" label="房间类型" align="center"/>
      <el-table-column prop="roomNumber" label="房间号" align="center"/>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.length"
        style="margin-top: 20px;margin-left: 5px;"
    />
  </el-card>
</template>

<script setup>
import {onMounted, ref} from "vue";

const searchForm = ref({number: '', status: ''})

const resetSearch = () => {
  searchForm.value = {number: '', status: ''}
  loadBed()
}
//表格数据
const tableData = ref([]);
const currentTableData = ref([]) // 当前页显示的数据
const currentPage = ref(1)      // 当前页码
const pageSize = ref(10)        // 每页条数
//加载表格数据
const loadBed = () => {
  for (let i = 1; i <= 15; i++) {
    const s = i % 2 === 0 ? '空床' : '已占用';
    tableData.value.push({bedNumber: i, status: s,floor:'2',type:'六人间',roomNumber:'1101'})
  }
}
onMounted(() => {
  loadBed()
})

// 获取数据（示例）
const fetchData = async () => {
  // 这里替换为你的API请求
  // dataTable.value = await api.getData();
  updateCurrentData();
}

// 更新当前页数据
const updateCurrentData = () => {
  const start = (currentPage.value - 1) * pageSize.value
  const end = start + pageSize.value
  currentTableData.value = tableData.value.slice(start, end)
}

// 每页条数变化
const handleSizeChange = (val) => {
  pageSize.value = val
  updateCurrentData()
}

// 页码变化
const handleCurrentChange = (val) => {
  currentPage.value = val
  updateCurrentData()
}

// 生命周期钩子
onMounted(() => {
  fetchData()
})
</script>


<style scoped>

</style>